package com.luculent.action;

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.imageio.ImageIO;
import javax.script.ScriptException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang3.StringUtils;
import org.apache.http.Consts;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.luculent.base.section.FPBSend;
import com.luculent.result.Response;
import com.luculent.utils.EncryptUtils;
import com.luculent.utils.FPBTableUtils;

import lombok.extern.slf4j.Slf4j;  

@Controller 
@RequestMapping("/cf_fpb/neimenggulangkunfupin")
@Slf4j
public class FPBController extends FPBSend{
	
	private static String HMAC_KEY = "hvalzJBBKp3TxR5v";
	
	
	@RequestMapping(params ="iw-cmd=vcode1") 
    public void code1(HttpServletResponse response,HttpServletRequest request) throws UnsupportedOperationException, IOException{
//		HttpClient client = getClient();
//		HttpPost siginPost = new HttpPost("http://106.38.235.201:7080/cpad_new/api/security/getValidateToken");
//		siginPost.setHeader("Content-Type", "application/json");
//		siginPost.setHeader("User-Agent", agent);
//		siginPost.setHeader("Host","localhost"); 
//		HttpResponse HtmlResp  = client.execute(siginPost); 
//		String validateToken = EntityUtils.toString(HtmlResp.getEntity()); 
//		if(StringUtils.isNotBlank(validateToken)){  
			HttpClient clientCode = getClient();
			String imgUrl = "http://106.38.235.201:7080/cas/jcaptcha/"+Math.random();
			log.debug(imgUrl);
			HttpGet siginPostCode = new HttpGet(imgUrl);
			//siginPostCode.setHeader("Content-Type", "text/html");
			siginPostCode.setHeader("User-Agent",agent);
			siginPostCode.setHeader("Host","106.38.235.201:7080"); 
			HttpResponse HtmlRespCode = clientCode.execute(siginPostCode); 
			 
			String cookie = showCookies(HtmlRespCode.getAllHeaders()); 
			//super.validateToken = validateToken;
			super.cookie = cookie; 
			response.setHeader("Pragma", "no-cache");
	        response.setHeader("Cache-Control", "no-cache");
			response.setHeader("Content-Type","image/jpeg;charset=UTF-8");//设置响应的媒体类型，这样浏览器会识别出响应的是图片
			log.debug(HtmlRespCode.getEntity().toString());
			BufferedImage buffImg = ImageIO.read(HtmlRespCode.getEntity().getContent());
			ServletOutputStream sos = response.getOutputStream();
	        ImageIO.write(buffImg, "jpeg", sos);
	        sos.close(); 
//		} 
//		response.getOutputStream().write(IOUtils.toByteArray(HtmlResp.getEntity().getContent()));
//		response.flushBuffer(); 
    } 
	
	@RequestMapping(params ="iw-cmd=login_p") 
	@ResponseBody
    public String login_p(HttpSession session) throws NoSuchMethodException, ScriptException, Exception{
		Response response = new Response();
		response.head.rtnCode = "000000";
		
//		if(super.cookie == null /*|| super.validateToken == null*/){
//			response.head.rtnCode = "900001"; 
//	    	response.head.rtnMsg = "cookie验证码错误";
//	    	return response.toJson();
//		}
//		if(StringUtils.isBlank(username)||StringUtils.isBlank(password) || StringUtils.isBlank(code)){
//			response.head.rtnCode = "900004"; 
//	    	response.head.rtnMsg = "未输入参数或参数格式有误";
//	    	return response.toJson();
//		}
		  
		DefaultHttpClient client = new DefaultHttpClient();
		HttpGet siginPost = new HttpGet("http://106.38.235.201:7080/cas/");
		  
		
//		ReqEntity reqEntity = new ReqEntity();
//		reqEntity.username = (String)EncryptUtils.getAesEngine().invokeFunction("encrypt", username,HMAC_KEY);
//		reqEntity.password =(String)EncryptUtils.getAesEngine().invokeFunction("encrypt", password,HMAC_KEY);;
//		reqEntity.jcaptcha_response = code;
//		//reqEntity.validateToken = super.validateToken;
//		siginPost.setEntity(new StringEntity(new Gson().toJson(reqEntity)));
		
		HttpResponse HtmlResp = client.execute(siginPost);  
		if(HtmlResp.getEntity() != null){ 
			//log.debug(EntityUtils.toString(HtmlResp.getEntity(), "UTF-8"));
			String cookie = showCookies(HtmlResp.getAllHeaders()); 
			super.cookie = cookie; 
			Document doc = Jsoup.parse(EntityUtils.toString(HtmlResp.getEntity(), "UTF-8"));
			Elements elements = doc.select("input[name=lt]"); 
			String title = "";
			log.debug(elements.toString());
			for(Element element : elements ){
				title = element.val();
				log.debug(title);
			}
			super.csrf = title;
			
	    }else{
	    	response.head.rtnCode = "999999"; 
	    	response.head.rtnMsg = "系统返回异常"; 
	    }   
		return response.toJson();
    }
	
	@RequestMapping(params ="iw-cmd=login_p1") 
	@ResponseBody
    public String login_p1(HttpSession session,
    		@RequestParam(value="yzm",required = true) String code) throws NoSuchMethodException, ScriptException, Exception{
		Response response = new Response();
		response.head.rtnCode = "000000";
		 
		  
		DefaultHttpClient client = new DefaultHttpClient();
		HttpPost post1 = new HttpPost("http://106.38.235.201:7080/cas/login");
		
		List<BasicNameValuePair> list = new ArrayList<BasicNameValuePair>();
		list.add(new BasicNameValuePair("type", "1"));
		list.add(new BasicNameValuePair("username",(String)EncryptUtils.getAesEngine().invokeFunction("encrypt", "150402000",HMAC_KEY)));
		list.add(new BasicNameValuePair("password",(String)EncryptUtils.getAesEngine().invokeFunction("encrypt", "HSFPBfpb654321.",HMAC_KEY)));
		list.add(new BasicNameValuePair("jcaptcha_response", code));
		list.add(new BasicNameValuePair("lt",super.csrf));
		UrlEncodedFormEntity refe = new UrlEncodedFormEntity(list,Consts.UTF_8); 
		post1.setEntity(refe);
		HttpResponse resp1 = client.execute(post1);  
		if(resp1.getEntity() != null){  
			String cookie = showCookies(resp1.getAllHeaders()); 
			super.cookie = cookie; 
			Document doc = Jsoup.parse(EntityUtils.toString(resp1.getEntity(), "UTF-8"));
			Elements elements = doc.select("p").select("a"); 
			String title = "";
			for(Element element : elements ){
				title = element.text();
				log.debug(title);
			}
			HttpClient client2 =  getClient();
			HttpPost post2 = new HttpPost(title);
			HttpResponse resp2 = client2.execute(post2);  
			log.debug(EntityUtils.toString(resp2.getEntity(), "UTF-8"));
			if(resp1.getEntity() != null){  
				String cookie2 = showCookies(resp2.getAllHeaders()); 
				super.cookie = cookie2;
			}
		} 
//		List<BasicNameValuePair> list = new ArrayList<BasicNameValuePair>();
//		list.add(new BasicNameValuePair("j_username", "150402000"));
//		list.add(new BasicNameValuePair("j_password", "HSFPBfpb654321."));
//		UrlEncodedFormEntity refe = new UrlEncodedFormEntity(list,Consts.UTF_8);
		//siginPost.setEntity(refe);
		return response.toJson();
    }
	
	@RequestMapping(params ="iw-cmd=login_after") 
	@ResponseBody
    public String login_before(HttpSession session,@RequestParam(value="username",required = true) String username,
    		@RequestParam(value="Password",required = true) String password,
    		@RequestParam(value="yzm",required = true) String code) throws NoSuchMethodException, ScriptException, Exception{
		Response response = new Response();
		response.head.rtnCode = "000000";
		
//		if(super.cookie == null /*|| super.validateToken == null*/){
//			response.head.rtnCode = "900001"; 
//	    	response.head.rtnMsg = "cookie验证码错误";
//	    	return response.toJson();
//		}
//		if(StringUtils.isBlank(username)||StringUtils.isBlank(password) || StringUtils.isBlank(code)){
//			response.head.rtnCode = "900004"; 
//	    	response.head.rtnMsg = "未输入参数或参数格式有误";
//	    	return response.toJson();
//		}
		  
		HttpClient client =  getClient();
		HttpPost siginPost = new HttpPost("http://106.38.235.201:7080/portal/j_spring_security_check");
		
		siginPost.setHeader("User-Agent",agent);
		//siginPost.setHeader("Cookie",session.getAttribute("cookie").toString());
		siginPost.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
		siginPost.setHeader("Host","106.38.235.201:7080"); 
		List<BasicNameValuePair> list = new ArrayList<BasicNameValuePair>();
		list.add(new BasicNameValuePair("j_username", "150402000"));
		list.add(new BasicNameValuePair("j_password", "HSFPBfpb654321."));
		UrlEncodedFormEntity refe = new UrlEncodedFormEntity(list,Consts.UTF_8);
//		ReqEntity reqEntity = new ReqEntity();
//		reqEntity.username = (String)EncryptUtils.getAesEngine().invokeFunction("encrypt", username,HMAC_KEY);
//		reqEntity.password =(String)EncryptUtils.getAesEngine().invokeFunction("encrypt", password,HMAC_KEY);;
//		reqEntity.jcaptcha_response = code;
//		//reqEntity.validateToken = super.validateToken;
//		siginPost.setEntity(new StringEntity(new Gson().toJson(reqEntity)));
		siginPost.setEntity(refe);
		HttpResponse HtmlResp = client.execute(siginPost);  
		if(HtmlResp.getEntity() != null){ 
			String cookie = showCookies(HtmlResp.getAllHeaders()); 
			super.cookie = cookie; 
			Document doc = Jsoup.parse(EntityUtils.toString(HtmlResp.getEntity(), "UTF-8"));
			Elements elements = doc.select("p").select("a"); 
			String title = "";
			for(Element element : elements ){
				title = element.text();
				log.debug(title);
			}
			HttpClient client1 =  getClient();
			HttpPost post1 = new HttpPost(title);
			HttpResponse resp1 = client1.execute(post1);  
			log.debug(resp1.getEntity().toString());
			if(resp1.getEntity() != null){ 
				String cookie1 = showCookies(resp1.getAllHeaders()); 
				super.cookie = cookie1;
			}
	    }else{
	    	response.head.rtnCode = "999999"; 
	    	response.head.rtnMsg = "系统返回异常"; 
	    }  
		return response.toJson();
    }
	
	
	@RequestMapping(params ="iw-cmd=login1") 
	@ResponseBody
    public String login1(HttpSession session,@RequestParam(value="username",required = true) String username,
    		@RequestParam(value="Password",required = true) String password,
    		@RequestParam(value="yzm",required = true) String code) throws NoSuchMethodException, ScriptException, Exception{
		Response response = new Response();
		response.head.rtnCode = "000000";
		
//		if(super.cookie == null /*|| super.validateToken == null*/){
//			response.head.rtnCode = "900001"; 
//	    	response.head.rtnMsg = "cookie验证码错误";
//	    	return response.toJson();
//		}
//		if(StringUtils.isBlank(username)||StringUtils.isBlank(password) || StringUtils.isBlank(code)){
//			response.head.rtnCode = "900004"; 
//	    	response.head.rtnMsg = "未输入参数或参数格式有误";
//	    	return response.toJson();
//		}
		  
		HttpClient client =  getClient();
		HttpPost siginPost = new HttpPost("http://106.38.235.201:7080/portal/j_spring_security_check");
		
		siginPost.setHeader("User-Agent",agent);
		//siginPost.setHeader("Cookie",session.getAttribute("cookie").toString());
		siginPost.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
		siginPost.setHeader("Host","106.38.235.201:7080"); 
		List<BasicNameValuePair> list = new ArrayList<BasicNameValuePair>();
		list.add(new BasicNameValuePair("j_username", "150402000"));
		list.add(new BasicNameValuePair("j_password", "HSFPBfpb654321."));
		UrlEncodedFormEntity refe = new UrlEncodedFormEntity(list,Consts.UTF_8);
//		ReqEntity reqEntity = new ReqEntity();
//		reqEntity.username = (String)EncryptUtils.getAesEngine().invokeFunction("encrypt", username,HMAC_KEY);
//		reqEntity.password =(String)EncryptUtils.getAesEngine().invokeFunction("encrypt", password,HMAC_KEY);;
//		reqEntity.jcaptcha_response = code;
//		//reqEntity.validateToken = super.validateToken;
//		siginPost.setEntity(new StringEntity(new Gson().toJson(reqEntity)));
		siginPost.setEntity(refe);
		HttpResponse HtmlResp = client.execute(siginPost);  
		if(HtmlResp.getEntity() != null){ 
			String cookie = showCookies(HtmlResp.getAllHeaders()); 
			super.cookie = cookie; 
			Document doc = Jsoup.parse(EntityUtils.toString(HtmlResp.getEntity(), "UTF-8"));
			Elements elements = doc.select("p").select("a"); 
			String title = "";
			for(Element element : elements ){
				title = element.text();
				log.debug(title);
			}
			HttpClient client1 =  getClient();
			HttpPost post1 = new HttpPost(title);
			HttpResponse resp1 = client1.execute(post1);  
			log.debug(resp1.getEntity().toString());
			if(resp1.getEntity() != null){ 
				String cookie1 = showCookies(resp1.getAllHeaders()); 
				super.cookie = cookie1;
			}
			
			
			
			
			HttpClient getMemuClient =  getClient();
			HttpPost menuPost = new HttpPost("http://106.38.235.201:7080/portal/techcomp/idm/newMenuNavigatorProcessor!getSysReqParameter.action");
			
			List<BasicNameValuePair> list1 = new ArrayList<BasicNameValuePair>();
			list.add(new BasicNameValuePair("sysId", "1000000002"));
			list.add(new BasicNameValuePair("sysType", "1"));
			list.add(new BasicNameValuePair("unitcode", "150402000000"));
			UrlEncodedFormEntity refe1 = new UrlEncodedFormEntity(list1,Consts.UTF_8); 
			menuPost.setEntity(refe1);
			HttpResponse menuResp = getMemuClient.execute(menuPost);  
			if(menuResp.getEntity() != null){ 
				String cookie1 = showCookies(menuResp.getAllHeaders()); 
				super.cookie = cookie1;
			}
			
			String jsonStr = EntityUtils.toString(menuResp.getEntity(), "UTF-8"); 
			log.debug(jsonStr);
			JsonParser jp=new JsonParser(); 
			if(StringUtils.isBlank(jsonStr)){
				response.head.rtnCode = "900001";
				response.head.rtnMsg = "验证码错误";
				return response.toJson();
			}
			log.debug(jsonStr);
			JsonObject jo=jp.parse(jsonStr).getAsJsonObject();
			if(!jo.get("options").getAsJsonObject().get("errorMsg").isJsonNull()){
				String errorMsg=jo.get("options").getAsJsonObject().get("errorMsg").getAsString();
				if(errorMsg.contains("验证码过期")){
					response.head.rtnCode = "900001";
					response.head.rtnMsg = "验证码错误";
					return response.toJson();
				}else{
					response.head.rtnCode = "900006";
					response.head.rtnMsg = errorMsg;
					return response.toJson();
				}
			}else if(jo.get("options").getAsJsonObject().get("code").getAsInt()!=1){
				response.head.rtnCode = "900002";
				response.head.rtnMsg = "用户名或密码错误";
				return response.toJson();
			}
			String token=HtmlResp.getFirstHeader("token").getValue(); 
			if(StringUtils.isNotBlank(token)){
				super.token = token ;
				response.head.rtnCode = "000000";
				response.head.rtnMsg = "请求成功";
			}
	    }else{
	    	response.head.rtnCode = "999999"; 
	    	response.head.rtnMsg = "系统返回异常"; 
	    }  
		return response.toJson();
    }
	
	
	
	@RequestMapping(params ="iw-cmd=vcode") 
    public void code(HttpServletResponse response,HttpServletRequest request) throws UnsupportedOperationException, IOException{
		HttpClient client = getClient();
		HttpPost siginPost = new HttpPost("http://localhost/cpad_new/api/security/getValidateToken");
		siginPost.setHeader("Content-Type", "application/json");
		siginPost.setHeader("User-Agent", agent);
		siginPost.setHeader("Host","localhost"); 
		HttpResponse HtmlResp  = client.execute(siginPost); 
		String validateToken = EntityUtils.toString(HtmlResp.getEntity()); 
		if(StringUtils.isNotBlank(validateToken)){  
			HttpClient clientCode = getClient();
			HttpGet siginPostCode = new HttpGet("http://localhost/cpad_new/api/security/getValidateCode/"+validateToken);
			siginPostCode.setHeader("Content-Type", "application/json");
			siginPostCode.setHeader("User-Agent",agent);
			siginPostCode.setHeader("Host","localhost"); 
			HttpResponse HtmlRespCode = clientCode.execute(siginPostCode); 
			String cookie = showCookies(HtmlRespCode.getAllHeaders()); 
			super.validateToken = validateToken;
			super.cookie = cookie; 
			response.setHeader("Pragma", "no-cache");
	        response.setHeader("Cache-Control", "no-cache");
			response.setHeader("Content-Type","image/jpeg;charset=UTF-8");//设置响应的媒体类型，这样浏览器会识别出响应的是图片
			BufferedImage buffImg = ImageIO.read(HtmlRespCode.getEntity().getContent());
			ServletOutputStream sos = response.getOutputStream();
	        ImageIO.write(buffImg, "jpeg", sos);
	        sos.close(); 
		} 
//		response.getOutputStream().write(IOUtils.toByteArray(HtmlResp.getEntity().getContent()));
//		response.flushBuffer(); 
    } 
	
	@RequestMapping(params ="iw-cmd=login") 
	@ResponseBody
    public String login(HttpSession session,@RequestParam(value="username",required = true) String username,
    		@RequestParam(value="Password",required = true) String password,
    		@RequestParam(value="yzm",required = true) String code) throws NoSuchMethodException, ScriptException, Exception{
		Response response = new Response();
		response.head.rtnCode = "000000";
		
		if(super.cookie == null || super.validateToken == null){
			response.head.rtnCode = "900001"; 
	    	response.head.rtnMsg = "cookie验证码错误";
	    	return response.toJson();
		}
		if(StringUtils.isBlank(username)||StringUtils.isBlank(password) || StringUtils.isBlank(code)){
			response.head.rtnCode = "900004"; 
	    	response.head.rtnMsg = "未输入参数或参数格式有误";
	    	return response.toJson();
		}
		
		HttpClient client =  getClient();
		HttpPost siginPost = new HttpPost("http://localhost/cpad_new/api/security/login");
		
		siginPost.setHeader("User-Agent",agent);
		//siginPost.setHeader("Cookie",session.getAttribute("cookie").toString());
		siginPost.setHeader("Content-Type", "application/json");
		ReqEntity reqEntity = new ReqEntity();
		reqEntity.account = (String)EncryptUtils.getAesEngine().invokeFunction("encrypt", username,HMAC_KEY);
		reqEntity.password =(String)EncryptUtils.getAesEngine().invokeFunction("encrypt", password,HMAC_KEY);;
		reqEntity.inputCode = code;
		reqEntity.validateToken = super.validateToken;
		siginPost.setEntity(new StringEntity(new Gson().toJson(reqEntity)));
		HttpResponse HtmlResp = client.execute(siginPost);  
		if(HtmlResp.getEntity() != null){ 
			String cookie = showCookies(HtmlResp.getAllHeaders()); 
			super.cookie = cookie;
			String jsonStr = EntityUtils.toString(HtmlResp.getEntity(), "UTF-8"); 
			JsonParser jp=new JsonParser(); 
			if(StringUtils.isBlank(jsonStr)){
				response.head.rtnCode = "900001";
				response.head.rtnMsg = "验证码错误";
				return response.toJson();
			}
			JsonObject jo=jp.parse(jsonStr).getAsJsonObject();
			if(!jo.get("options").getAsJsonObject().get("errorMsg").isJsonNull()){
				String errorMsg=jo.get("options").getAsJsonObject().get("errorMsg").getAsString();
				if(errorMsg.contains("验证码过期")){
					response.head.rtnCode = "900001";
					response.head.rtnMsg = "验证码错误";
					return response.toJson();
				}else{
					response.head.rtnCode = "900006";
					response.head.rtnMsg = errorMsg;
					return response.toJson();
				}
			}else if(jo.get("options").getAsJsonObject().get("code").getAsInt()!=1){
				response.head.rtnCode = "900002";
				response.head.rtnMsg = "用户名或密码错误";
				return response.toJson();
			}
			String token=HtmlResp.getFirstHeader("token").getValue(); 
			if(StringUtils.isNotBlank(token)){
				super.token = token ;
				response.head.rtnCode = "000000";
				response.head.rtnMsg = "请求成功";
			}
	    }else{
	    	response.head.rtnCode = "999999"; 
	    	response.head.rtnMsg = "系统返回异常"; 
	    }  
		return response.toJson();
    }
	public class ReqEntity{
		String account = "";
		String password = "";
		String inputCode = "";
		String validateToken = "";
	}
	
	@RequestMapping(params ="iw-cmd=pinkunhuxinxiliebiao") 
	@ResponseBody
    public String pinkunhuxinxiliebiao(@RequestParam(value="YM",required = false) String ym,
    		@RequestParam(value="ND",required = false) String nd,
    		@RequestParam(value="SZXIAN",required = false) String xian) throws ClientProtocolException, IOException{
		Response response = new Response();
		response.head.rtnCode = "000000"; 
		if(super.cookie == null || super.token == null){
			response.head.rtnCode = "900001"; 
	    	response.head.rtnMsg = "未登录或登录超时";
	    	return response.toJson();
		} 
		int yma = 0;
		int pageSize = 100;
		if(StringUtils.isNotBlank(ym)){
			yma = (Integer.valueOf(ym).intValue() - 1) * pageSize;
		}
		HttpClient client =  getClient();
		HttpPut siginPost = new HttpPut("http://localhost/cpad_new/api/common/doQuery");
		siginPost =(HttpPut) getHeader(siginPost); 
		
		String condtion = "{\"options\":{\"OPT\":\"query\",\"type\":\"dao\"},\"body\":{\"poorFamilyList\":{\"conditions\":{\"query_AAR040\":\""+nd+"\",\"AAR002\":\"150000000000\",\"AAR003\":\"150400000000\",\"AAR004\":\""+xian+"\",\"AAR005\":null,\"AAR006\":null,\"AAR007\":null,\"aac006\":[],\"aac005\":\"\",\"aar010\":[],\"aab002\":\"\",\"aab004\":\"\",\"aar008\":\""+xian.substring(0,6)+"\",\"condition_diy\":[],\"aar040\":\""+nd+"\"},\"namespace\":\"com.neusoft.biz.core.mapping.Ac01Mapper\",\"sqlId\":\"queryGrid\",\"page\":{\"pageSize\":"+pageSize+",\"startRow\":"+yma+"}},\"numberForm\":{\"conditions\":{\"query_AAR040\":\""+nd+"\",\"AAR002\":\"150000000000\",\"AAR003\":\"150400000000\",\"AAR004\":\""+xian+"\",\"AAR005\":null,\"AAR006\":null,\"AAR007\":null,\"aac006\":[],\"aac005\":\"\",\"aar010\":[],\"aab002\":\"\",\"aab004\":\"\",\"aar008\":\""+xian.substring(0,6)+"\",\"condition_diy\":[],\"aar040\":\""+nd+"\"},\"namespace\":\"com.neusoft.biz.core.mapping.Ac01Mapper\",\"sqlId\":\"queryNumber\"}}}";
		siginPost.setEntity(new StringEntity(condtion));
		HttpResponse HtmlResp = client.execute(siginPost);  
		if(HtmlResp.getEntity() != null){ 
			String jsonStr = EntityUtils.toString(HtmlResp.getEntity(), "UTF-8");  
			JsonParser jp=new JsonParser(); 
			if(StringUtils.isBlank(jsonStr)){
				response.head.rtnCode = "999999";
				response.head.rtnMsg = "请求异常";
				return response.toJson();
			}
			JsonObject jo=jp.parse(jsonStr).getAsJsonObject(); 
			int code = Integer.valueOf(jo.get("options").getAsJsonObject().get("code").toString());
			if(code == 1){
				JsonArray data = jo.get("body").getAsJsonObject().get("poorFamilyList").getAsJsonObject().get("data").getAsJsonArray();
				if(data == null || data.size() == 0){
		        	response.head.rtnCode = "900005"; 
					response.head.rtnMsg = "没有当前查询信息";
					return response.toJson();
		        }
				response.head.rtnCode = "000000"; 
				response.head.rtnMsg = "请求成功";
				response.body.size=pageSize+""; 
				JsonArray total = jo.get("body").getAsJsonObject().get("numberForm").getAsJsonObject().get("data").getAsJsonArray();
				response.body.totalCount=total.get(0).getAsJsonObject().get("HNUM").toString();
				response.body.sql = FPBTableUtils.pinkunhuxinxiliebiao(data,xian); 
				log.debug(response.body.sql);
				return response.toJson();
			}else{
				if(!jo.get("options").getAsJsonObject().get("errorMsg").isJsonNull()){
					String errorMsg=jo.get("options").getAsJsonObject().get("errorMsg").getAsString();
					if(errorMsg.contains("验证码过期")){
						response.head.rtnCode = "900001";
						response.head.rtnMsg = "验证码错误";
						return response.toJson();
					}else{
						response.head.rtnCode = "900006";
						response.head.rtnMsg = errorMsg;
						return response.toJson();
					}
				}else if(jo.get("options").getAsJsonObject().get("code").getAsInt()!=1){
					response.head.rtnCode = "900002";
					response.head.rtnMsg = "用户名或密码错误";
					return response.toJson();
				} 
			} 
	    }else{
	    	response.head.rtnCode = "999999"; 
	    	response.head.rtnMsg = "系统返回异常"; 
	    }  
		return response.toJson();
    } 
	
	
	@RequestMapping(params ="iw-cmd=bangfurendanweichaxun") 
	@ResponseBody
    public String bangfurendanweichaxun(@RequestParam(value="YM",required = false) String ym) throws ClientProtocolException, IOException{
		Response response = new Response();
		response.head.rtnCode = "000000"; 
		if(super.cookie == null || super.token == null){
			response.head.rtnCode = "900001"; 
	    	response.head.rtnMsg = "未登录或登录超时";
	    	return response.toJson();
		} 
		int yma = 0;
		int pageSize = 100;
		if(StringUtils.isNotBlank(ym)){
			yma = (Integer.valueOf(ym).intValue() - 1) * pageSize;
		}
		HttpClient client =  getClient();
		HttpPut siginPost = new HttpPut("http://localhost/cpad_new/api/common/doQuery");
		siginPost =(HttpPut) getHeader(siginPost);
		String condtion = "{\"options\":{\"OPT\":\"query\",\"type\":\"dao\"},\"body\":{\"aidUnitsList\":{\"conditions\":{\"aap004\":\"\",\"aap001\":\"\",\"aar012\":\"\",\"level\":\"40\",\"distrct\":\"150400000000\",\"AP11AAR002\":\"15\",\"AP11AAR003\":\"1504\",\"AP11AAR004\":\"1504\",\"AP11AAR005\":\"1504\",\"AP11ARMY\":\"1504\",\"AP11AAR006\":\"1504\"},\"namespace\":\"com.neusoft.biz.core.mapping.Ap11Mapper\",\"sqlId\":\"queryAidUnitsALLGrid\",\"page\":{\"pageSize\":"+pageSize+",\"startRow\":"+yma+"}}}}";
		siginPost.setEntity(new StringEntity(condtion));
		HttpResponse HtmlResp = client.execute(siginPost);  
		if(HtmlResp.getEntity() != null){ 
			String jsonStr = EntityUtils.toString(HtmlResp.getEntity(), "UTF-8"); 
			JsonParser jp=new JsonParser(); 
			if(StringUtils.isBlank(jsonStr)){
				response.head.rtnCode = "999999";
				response.head.rtnMsg = "请求异常";
				return response.toJson();
			}
			JsonObject jo=jp.parse(jsonStr).getAsJsonObject(); 
			int code = Integer.valueOf(jo.get("options").getAsJsonObject().get("code").toString());
			if(code == 1){
				JsonArray data = jo.get("body").getAsJsonObject().get("aidUnitsList").getAsJsonObject().get("data").getAsJsonArray();
				if(data == null || data.size() == 0){
		        	response.head.rtnCode = "900005"; 
					response.head.rtnMsg = "没有当前查询信息";
					return response.toJson();
		        }
				response.head.rtnCode = "000000"; 
				response.head.rtnMsg = "请求成功";
				response.body.size=pageSize+"";
				response.body.totalCount="-1";
				response.body.sql = FPBTableUtils.bangfurendanweichaxun(data); 
				return response.toJson();
			}else{
				if(!jo.get("options").getAsJsonObject().get("errorMsg").isJsonNull()){
					String errorMsg=jo.get("options").getAsJsonObject().get("errorMsg").getAsString();
					if(errorMsg.contains("验证码过期")){
						response.head.rtnCode = "900001";
						response.head.rtnMsg = "验证码错误";
						return response.toJson();
					}else{
						response.head.rtnCode = "900006";
						response.head.rtnMsg = errorMsg;
						return response.toJson();
					}
				}else if(jo.get("options").getAsJsonObject().get("code").getAsInt()!=1){
					response.head.rtnCode = "900002";
					response.head.rtnMsg = "用户名或密码错误";
					return response.toJson();
				} 
			} 
	    }else{
	    	response.head.rtnCode = "999999"; 
	    	response.head.rtnMsg = "系统返回异常"; 
	    }  
		return response.toJson();
    } 
	@RequestMapping(params ="iw-cmd=bangfuzerenrenliebiao") 
	@ResponseBody
    public String bangfuzerenrenliebiao(@RequestParam(value="YM",required = false) String ym,@RequestParam(value="DWID",required = false) String dwId) throws ClientProtocolException, IOException{
		Response response = new Response();
		response.head.rtnCode = "000000"; 
		if(super.cookie == null || super.token == null){
			response.head.rtnCode = "900001"; 
	    	response.head.rtnMsg = "未登录或登录超时";
	    	return response.toJson();
		}
		if(StringUtils.isBlank(dwId)){
			response.head.rtnCode = "900004"; 
	    	response.head.rtnMsg = "未输入参数或参数格式有误";
	    	return response.toJson();
		}
		int yma = 0;
		int pageSize = 100;
		if(StringUtils.isNotBlank(ym)){
			yma = (Integer.valueOf(ym).intValue() - 1) * pageSize;
		}
		HttpClient client =  getClient();
		HttpPut siginPost = new HttpPut("http://localhost/cpad_new/api/common/doQuery");
		siginPost =(HttpPut) getHeader(siginPost); 
		String condtion = "{\"options\":{\"OPT\":\"query\",\"type\":\"dao\"},\"body\":{\"responsiblePersonList\":{\"conditions\":{\"AAP004\":\"20\",\"AAR008\":\"150000000000\",\"AAP110\":"+dwId+",\"AAR024\":20161217201443,\"AAP001\":\"国网内蒙古东部电力公司\",\"AAR025\":\"内蒙古自治区\",\"BAZ002\":4301100741225881,\"ROW_ID\":13,\"AREA\":\"内蒙古自治区\",\"AAP051\":\"40\",\"AAR011\":\"魏晓东\",\"AAR012\":\"13948249018\",\"AAR001\":\"150000000000\",\"AAR023\":\"150000\",\"_$visited\":true},\"namespace\":\"com.neusoft.biz.core.mapping.Ak11Mapper\",\"sqlId\":\"queryResponsiblePersonList\",\"page\":{\"pageSize\":"+pageSize+",\"startRow\":"+yma+"}}}}";
		siginPost.setEntity(new StringEntity(condtion));
		HttpResponse HtmlResp = client.execute(siginPost);  
		if(HtmlResp.getEntity() != null){ 
			String jsonStr = EntityUtils.toString(HtmlResp.getEntity(), "UTF-8"); 
			JsonParser jp=new JsonParser(); 
			if(StringUtils.isBlank(jsonStr)){
				response.head.rtnCode = "999999";
				response.head.rtnMsg = "请求异常";
				return response.toJson();
			}
			JsonObject jo=jp.parse(jsonStr).getAsJsonObject(); 
			int code = Integer.valueOf(jo.get("options").getAsJsonObject().get("code").toString());
			if(code == 1){
				JsonArray data = jo.get("body").getAsJsonObject().get("responsiblePersonList").getAsJsonObject().get("data").getAsJsonArray();
				if(data == null || data.size() == 0){
		        	response.head.rtnCode = "900005"; 
					response.head.rtnMsg = "没有当前查询信息";
					return response.toJson();
		        }
				response.head.rtnCode = "000000"; 
				response.head.rtnMsg = "请求成功";
				response.body.size=pageSize+"";
				response.body.totalCount="-1";
			    response.body.sql = FPBTableUtils.bangfuzerenrenliebiao(data,dwId); 
			    log.debug(response.body.sql);
				return response.toJson();
			}else{
				if(!jo.get("options").getAsJsonObject().get("errorMsg").isJsonNull()){
					String errorMsg=jo.get("options").getAsJsonObject().get("errorMsg").getAsString();
					if(errorMsg.contains("验证码过期")){
						response.head.rtnCode = "900001";
						response.head.rtnMsg = "验证码错误";
						return response.toJson();
					}else{
						response.head.rtnCode = "900006";
						response.head.rtnMsg = errorMsg;
						return response.toJson();
					}
				}else if(jo.get("options").getAsJsonObject().get("code").getAsInt()!=1){
					response.head.rtnCode = "900002";
					response.head.rtnMsg = "用户名或密码错误";
					return response.toJson();
				} 
			} 
	    }else{
	    	response.head.rtnCode = "999999"; 
	    	response.head.rtnMsg = "系统返回异常"; 
	    }  
		return response.toJson();
    } 
	
	
	@RequestMapping(params ="iw-cmd=beibangfurenliebiao") 
	@ResponseBody
    public String beibangfurenliebiao(@RequestParam(value="BFRID",required = false) String bfrId) throws ClientProtocolException, IOException{
		Response response = new Response();
		response.head.rtnCode = "000000"; 
		if(super.cookie == null || super.token == null){
			response.head.rtnCode = "900001"; 
	    	response.head.rtnMsg = "未登录或登录超时";
	    	return response.toJson();
		} 
		if(StringUtils.isBlank(bfrId)){
			response.head.rtnCode = "900004"; 
	    	response.head.rtnMsg = "未输入参数或参数格式有误";
	    	return response.toJson();
		}
		HttpClient client =  getClient();
		HttpPut siginPost = new HttpPut("http://localhost/cpad_new/api/common/doQuery");
		siginPost =(HttpPut) getHeader(siginPost); 
		String condtion = "{\"options\":{\"OPT\":\"query\",\"type\":\"dao\"},\"body\":{\"ResultList\":{\"conditions\":{\"AAP004\":\"50\",\"AAK031\":\"0\",\"AAR008\":\"150430000000\",\"AAK110\":"+bfrId+",\"AAP110\":3000415494,\"AAR013\":\"敖汉旗新惠镇\",\"AAK033\":\"01\",\"AAK032\":\"0\",\"AAP001\":\"敖汉旗金融办\",\"AAK037\":\"04\",\"AAK036\":\"20\",\"AAK039\":\"0\",\"AAB003\":\"1\",\"AAB002\":\"杨俊武\",\"AAB004\":\"150430197203023013\",\"ROW_ID\":3,\"AAF031\":\"142\",\"AAR011\":\"田野\",\"AAR012\":\"13847623195\",\"_$visited\":true},\"namespace\":\"com.neusoft.biz.core.mapping.Ak11Mapper\",\"sqlId\":\"personRelatedPoorFamily\"}}}";
		siginPost.setEntity(new StringEntity(condtion));
		HttpResponse HtmlResp = client.execute(siginPost);  
		if(HtmlResp.getEntity() != null){ 
			String jsonStr = EntityUtils.toString(HtmlResp.getEntity(), "UTF-8");  
			JsonParser jp=new JsonParser(); 
			if(StringUtils.isBlank(jsonStr)){
				response.head.rtnCode = "999999";
				response.head.rtnMsg = "请求异常";
				return response.toJson();
			}
			JsonObject jo=jp.parse(jsonStr).getAsJsonObject(); 
			int code = Integer.valueOf(jo.get("options").getAsJsonObject().get("code").toString());
			if(code == 1){
				JsonArray data = jo.get("body").getAsJsonObject().get("ResultList").getAsJsonObject().get("data").getAsJsonArray();
				if(data == null || data.size() == 0){
		        	response.head.rtnCode = "900005"; 
					response.head.rtnMsg = "没有当前查询信息";
					return response.toJson();
		        }
				response.head.rtnCode = "000000"; 
				response.head.rtnMsg = "请求成功";
				response.body.size=0+"";
				response.body.totalCount=data.size()+"";
			    response.body.sql = FPBTableUtils.beibangfurenliebiao(data,bfrId); 
			    log.debug(response.body.sql);
				return response.toJson();
			}else{
				if(!jo.get("options").getAsJsonObject().get("errorMsg").isJsonNull()){
					String errorMsg=jo.get("options").getAsJsonObject().get("errorMsg").getAsString();
					if(errorMsg.contains("验证码过期")){
						response.head.rtnCode = "900001";
						response.head.rtnMsg = "验证码错误";
						return response.toJson();
					}else{
						response.head.rtnCode = "900006";
						response.head.rtnMsg = errorMsg;
						return response.toJson();
					}
				}else if(jo.get("options").getAsJsonObject().get("code").getAsInt()!=1){
					response.head.rtnCode = "900002";
					response.head.rtnMsg = "用户名或密码错误";
					return response.toJson();
				} 
			} 
	    }else{
	    	response.head.rtnCode = "999999"; 
	    	response.head.rtnMsg = "系统返回异常"; 
	    }  
		return response.toJson();
    } 
	
	@RequestMapping(params ="iw-cmd=zcgzdbfdw") 
	@ResponseBody
    public String zcgzdbfdw(@RequestParam(value="SZXIAN",required = false) String xian,
    		@RequestParam(value="SZXIANG",required = false) String xiang,
    		@RequestParam(value="SZCUN",required = false) String cun,
    		@RequestParam(value="YM",required = false) String ym) throws ClientProtocolException, IOException{
		Response response = new Response();
		response.head.rtnCode = "000000"; 
		if(super.cookie == null || super.token == null){
			response.head.rtnCode = "900001"; 
	    	response.head.rtnMsg = "未登录或登录超时";
	    	return response.toJson();
		} 
		if(StringUtils.isBlank(cun)){
			response.head.rtnCode = "900004"; 
	    	response.head.rtnMsg = "未输入参数或参数格式有误";
	    	return response.toJson();
		}
		HttpClient client =  getClient();
		HttpPost siginPost = new HttpPost("http://localhost/cpad_new/api/object/assistmain/queryRuralTeam");
		siginPost =(HttpPost) getHeader(siginPost);
		String condtion = "{\"options\":{\"opt\":\"modifydata\"},\"ak11\":{\"AAR002\":\"150000000000\",\"AAR003\":\"150400000000\",\"AAR004\":\"150422000000\",\"AAR005\":\"150422002000\",\"AAR006\":\""+cun+"\",\"AAR007\":null,\"aar008\":\""+cun+"\"}}";
		siginPost.setEntity(new StringEntity(condtion));
		HttpResponse HtmlResp = client.execute(siginPost);  
		if(HtmlResp.getEntity() != null){ 
			String jsonStr = EntityUtils.toString(HtmlResp.getEntity(), "UTF-8");   
			JsonParser jp=new JsonParser(); 
			if(StringUtils.isBlank(jsonStr)){
				response.head.rtnCode = "999999";
				response.head.rtnMsg = "请求异常";
				return response.toJson();
			}
			JsonObject jo=jp.parse(jsonStr).getAsJsonObject(); 
			JsonArray data = jo.get("queryRuralTeamUnits").getAsJsonArray();
			if(data == null || data.size() == 0){
	        	response.head.rtnCode = "900005"; 
				response.head.rtnMsg = "没有当前查询信息";
				return response.toJson();
	        }
			response.head.rtnCode = "000000"; 
			response.head.rtnMsg = "请求成功";
			response.body.total=data.size()+"";
			response.body.page="1"; 
		    response.body.sql = FPBTableUtils.zcgzdbfdw(data,xian,xiang,cun); 
		    log.debug(response.body.sql);
			return response.toJson();
			 
	    }else{
	    	response.head.rtnCode = "999999"; 
	    	response.head.rtnMsg = "系统返回异常"; 
	    }  
		return response.toJson();
    } 
	
	@RequestMapping(params ="iw-cmd=zcgzzcdy") 
	@ResponseBody
    public String zcgzzcdy(@RequestParam(value="DWID",required = false) String dwid) throws ClientProtocolException, IOException{
		Response response = new Response();
		response.head.rtnCode = "000000"; 
		if(super.cookie == null || super.token == null){
			response.head.rtnCode = "900001"; 
	    	response.head.rtnMsg = "未登录或登录超时";
	    	return response.toJson();
		}  
		if(StringUtils.isBlank(dwid)){
			response.head.rtnCode = "900004"; 
	    	response.head.rtnMsg = "未输入参数或参数格式有误";
	    	return response.toJson();
		}  
		HttpClient client =  getClient();
		HttpPost siginPost = new HttpPost("http://localhost/cpad_new/api/object/assistmain/queryRuralTeam");
		siginPost =(HttpPost) getHeader(siginPost); 
		String condtion = "{\"options\":{\"opt\":\"modifydata\"},\"ak11\":{\"AAR002\":\"150000000000\",\"AAR003\":\"150400000000\",\"AAR004\":\"150422000000\",\"AAR005\":\"150422002000\",\"AAR006\":\""+dwid+"\",\"AAR007\":null,\"aar008\":\""+dwid+"\"}}";
		siginPost.setEntity(new StringEntity(condtion));
		HttpResponse HtmlResp = client.execute(siginPost);  
		if(HtmlResp.getEntity() != null){ 
			String jsonStr = EntityUtils.toString(HtmlResp.getEntity(), "UTF-8");  
			JsonParser jp=new JsonParser(); 
			if(StringUtils.isBlank(jsonStr)){
				response.head.rtnCode = "999999";
				response.head.rtnMsg = "请求异常";
				return response.toJson();
			}
			JsonObject jo=jp.parse(jsonStr).getAsJsonObject(); 
			JsonArray data = jo.get("queryRuralTeamMembers").getAsJsonArray();
			if(data == null || data.size() == 0){
	        	response.head.rtnCode = "900005"; 
				response.head.rtnMsg = "没有当前查询信息";
				return response.toJson();
	        }
			response.head.rtnCode = "000000"; 
			response.head.rtnMsg = "请求成功";
			response.body.total=data.size()+"";
			response.body.page="1"; 
		    response.body.sql = FPBTableUtils.zcgzzcdy(data,dwid); 
		    log.debug(response.body.sql);
			return response.toJson();
			 
	    }else{
	    	response.head.rtnCode = "999999"; 
	    	response.head.rtnMsg = "系统返回异常"; 
	    }  
		return response.toJson();
    } 
	/**
	 *  http://172.168.1.29:8080/cf_fpb/neimenggulangkunfupin?iw-apikey=123&iw-cmd=xiangmuxiangqing&SZXIAN=&XMLX=&ND=&YM=
	 * @param xian
	 * @param xmlx
	 * @param ym
	 * @param nd
	 * @return
	  
	 */
	@RequestMapping(params ="iw-cmd=xiangmuxinxichaxun") 
	@ResponseBody
    public String xiangmuxinxichaxun(@RequestParam(value="SZXIAN",required = false) String xian,
    		@RequestParam(value="XMLX",required = false) String xmlx,
    		@RequestParam(value="YM",required = false) String ym,@RequestParam(value="ND",required = false) String nd) throws ClientProtocolException, IOException{
		Response response = new Response();
		response.head.rtnCode = "000000"; 
		if(super.cookie == null || super.token == null){
			response.head.rtnCode = "900001"; 
	    	response.head.rtnMsg = "未登录或登录超时";
	    	return response.toJson();
		}
		if(StringUtils.isBlank(xian) || StringUtils.isBlank(xmlx)){
			response.head.rtnCode = "900004"; 
	    	response.head.rtnMsg = "未输入参数或参数格式有误";
	    	return response.toJson();
		}  
		int yma = 0;
		int pageSize = 100;
		if(StringUtils.isNotBlank(ym)){
			yma = (Integer.valueOf(ym).intValue() - 1) * pageSize;
		}
		HttpClient client =  getClient();
		HttpPut siginPost = new HttpPut("http://localhost/cpad_new/api/common/doQuery");
		siginPost =(HttpPut) getHeader(siginPost); 
		String condtion = "{\"options\":{\"OPT\":\"query\",\"type\":\"dao\"},\"body\":{\"resultList\":{\"conditions\":{\"aar040\":\""+nd+"\",\"AAR002\":\"150000000000\",\"AAR003\":\"150400000000\",\"AAR004\":\"150402000000\",\"AAR005\":null,\"acr005\":\""+xmlx+"\",\"acr009\":\"\",\"acr002\":\"\",\"aar008\":\""+xian.substring(0,6)+"\"},\"namespace\":\"com.neusoft.biz.core.mapping.Cr01Mapper\",\"sqlId\":\"searchProject\",\"page\":{\"pageSize\":"+pageSize+",\"startRow\":"+yma+"}}}}";
		siginPost.setEntity(new StringEntity(condtion));
		HttpResponse HtmlResp = client.execute(siginPost);  
		if(HtmlResp.getEntity() != null){ 
			String jsonStr = EntityUtils.toString(HtmlResp.getEntity(), "UTF-8");  
			JsonParser jp=new JsonParser(); 
			if(StringUtils.isBlank(jsonStr)){
				response.head.rtnCode = "999999";
				response.head.rtnMsg = "请求异常";
				return response.toJson();
			}
			JsonObject jo=jp.parse(jsonStr).getAsJsonObject(); 
			int code = Integer.valueOf(jo.get("options").getAsJsonObject().get("code").toString());
			if(code == 1){
				JsonArray data = jo.get("body").getAsJsonObject().get("resultList").getAsJsonObject().get("data").getAsJsonArray();
				if(data == null || data.size() == 0){
		        	response.head.rtnCode = "900005"; 
					response.head.rtnMsg = "没有当前查询信息";
					return response.toJson();
		        }
				response.head.rtnCode = "000000"; 
				response.head.rtnMsg = "请求成功";
				response.body.size=pageSize+"";
				response.body.totalCount="-1";
			    response.body.sql = FPBTableUtils.xiangmuxinxichaxun(data,xian,nd); 
			    log.debug(response.body.sql);
				return response.toJson();
			}else{
				if(!jo.get("options").getAsJsonObject().get("errorMsg").isJsonNull()){
					String errorMsg=jo.get("options").getAsJsonObject().get("errorMsg").getAsString();
					if(errorMsg.contains("验证码过期")){
						response.head.rtnCode = "900001";
						response.head.rtnMsg = "验证码错误";
						return response.toJson();
					}else{
						response.head.rtnCode = "900006";
						response.head.rtnMsg = errorMsg;
						return response.toJson();
					}
				}else if(jo.get("options").getAsJsonObject().get("code").getAsInt()!=1){
					response.head.rtnCode = "900002";
					response.head.rtnMsg = "用户名或密码错误";
					return response.toJson();
				} 
			} 
	    }else{
	    	response.head.rtnCode = "999999"; 
	    	response.head.rtnMsg = "系统返回异常"; 
	    }  
		return response.toJson();
    } 
	
	@RequestMapping(params ="iw-cmd=shouyirenliebiao") 
	@ResponseBody
    public String shouyirenliebiao(@RequestParam(value="XMBH",required = false) String xmbh,
    		@RequestParam(value="ND",required = false) String nd,@RequestParam(value="YM",required = false) String ym) throws ClientProtocolException, IOException{
		Response response = new Response();
		response.head.rtnCode = "000000"; 
		if(super.cookie == null || super.token == null){
			response.head.rtnCode = "900001"; 
	    	response.head.rtnMsg = "未登录或登录超时";
	    	return response.toJson();
		}
		if(StringUtils.isBlank(xmbh)){
			response.head.rtnCode = "900004"; 
	    	response.head.rtnMsg = "未输入参数或参数格式有误";
	    	return response.toJson();
		}  
		int yma = 0;
		int pageSize = 100;
		if(StringUtils.isNotBlank(ym)){
			yma = (Integer.valueOf(ym).intValue() - 1) * pageSize;
		}
		HttpClient client =  getClient();
		HttpPut siginPost = new HttpPut("http://localhost/cpad_new/api/common/doQuery");
		siginPost =(HttpPut) getHeader(siginPost);
		String condtion = "{\"options\":{\"OPT\":\"query\",\"type\":\"dao\"},\"body\":{\"beneficiaryList\":{\"conditions\":{\"aar040\":\""+nd+"\",\"acr010\":"+xmbh+"},\"namespace\":\"com.neusoft.biz.core.mapping.Cr05Mapper\",\"sqlId\":\"select_project_benefit\",\"page\":{\"pageSize\":"+pageSize+",\"startRow\":"+yma+"}}}}";
		 
		siginPost.setEntity(new StringEntity(condtion));
		HttpResponse HtmlResp = client.execute(siginPost);  
		if(HtmlResp.getEntity() != null){ 
			String jsonStr = EntityUtils.toString(HtmlResp.getEntity(), "UTF-8");  
			JsonParser jp=new JsonParser(); 
			if(StringUtils.isBlank(jsonStr)){
				response.head.rtnCode = "999999";
				response.head.rtnMsg = "请求异常";
				return response.toJson();
			}
			JsonObject jo=jp.parse(jsonStr).getAsJsonObject(); 
			int code = Integer.valueOf(jo.get("options").getAsJsonObject().get("code").toString());
			if(code == 1){
				JsonArray data = jo.get("body").getAsJsonObject().get("beneficiaryList").getAsJsonObject().get("data").getAsJsonArray();
				if(data == null || data.size() == 0){
		        	response.head.rtnCode = "900005"; 
					response.head.rtnMsg = "没有当前查询信息";
					return response.toJson();
		        }
				response.head.rtnCode = "000000"; 
				response.head.rtnMsg = "请求成功";
				response.body.size=pageSize+"";
				response.body.totalCount="-1";
				response.body.sql = FPBTableUtils.shouyirenliebiao(data,xmbh,nd); 
			    log.debug(response.body.sql);
				return response.toJson();
			}else{
				if(!jo.get("options").getAsJsonObject().get("errorMsg").isJsonNull()){
					String errorMsg=jo.get("options").getAsJsonObject().get("errorMsg").getAsString();
					if(errorMsg.contains("验证码过期")){
						response.head.rtnCode = "900001";
						response.head.rtnMsg = "验证码错误";
						return response.toJson();
					}else{
						response.head.rtnCode = "900006";
						response.head.rtnMsg = errorMsg;
						return response.toJson();
					}
				}else if(jo.get("options").getAsJsonObject().get("code").getAsInt()!=1){
					response.head.rtnCode = "900002";
					response.head.rtnMsg = "用户名或密码错误";
					return response.toJson();
				} 
			} 
	    }else{
	    	response.head.rtnCode = "999999"; 
	    	response.head.rtnMsg = "系统返回异常"; 
	    }  
		return response.toJson();
    } 
	/*不需要分页*/
	@RequestMapping(params ="iw-cmd=xiangmuxiangqing") 
	@ResponseBody
    public String xiangmuxiangqing(@RequestParam(value="XMBH",required = false) String xmbh,
    		@RequestParam(value="ND",required = false) String nd) throws ClientProtocolException, IOException{
		Response response = new Response();
		response.head.rtnCode = "000000"; 
		if(super.cookie == null || super.token == null){
			response.head.rtnCode = "900001"; 
	    	response.head.rtnMsg = "未登录或登录超时";
	    	return response.toJson();
		}
		if(StringUtils.isBlank(xmbh)){
			response.head.rtnCode = "900004"; 
	    	response.head.rtnMsg = "未输入参数或参数格式有误";
	    	return response.toJson();
		}   
		HttpClient client =  getClient();
		HttpPut siginPost = new HttpPut("http://localhost/cpad_new/api/common/doQuery");
		siginPost =(HttpPut) getHeader(siginPost); 
		String condtion = "{\"options\":{\"OPT\":\"query\",\"type\":\"dao\"},\"body\":{\"ProjectForm\":{\"conditions\":{\"aar040\":\""+nd+"\",\"acr010\":"+xmbh+"},\"namespace\":\"com.neusoft.biz.core.mapping.Cr01Mapper\",\"sqlId\":\"queryProjectByKey\",\"page\":{\"pageSize\":30,\"startRow\":0}}}}";
		 
		siginPost.setEntity(new StringEntity(condtion));
		HttpResponse HtmlResp = client.execute(siginPost);  
		if(HtmlResp.getEntity() != null){ 
			String jsonStr = EntityUtils.toString(HtmlResp.getEntity(), "UTF-8");  
			JsonParser jp=new JsonParser(); 
			if(StringUtils.isBlank(jsonStr)){
				response.head.rtnCode = "999999";
				response.head.rtnMsg = "请求异常";
				return response.toJson();
			}
			JsonObject jo=jp.parse(jsonStr).getAsJsonObject(); 
			int code = Integer.valueOf(jo.get("options").getAsJsonObject().get("code").toString());
			if(code == 1){
				JsonArray data = jo.get("body").getAsJsonObject().get("ProjectForm").getAsJsonObject().get("data").getAsJsonArray();
				if(data == null || data.size() == 0){
		        	response.head.rtnCode = "900005"; 
					response.head.rtnMsg = "没有当前查询信息";
					return response.toJson();
		        }
				response.head.rtnCode = "000000"; 
				response.head.rtnMsg = "请求成功";
				response.body.size="30";
				response.body.totalCount="1";
				response.body.sql = FPBTableUtils.xiangmuxiangqing(data,xmbh,nd); 
			    log.debug(response.body.sql);
				return response.toJson();
			}else{
				if(!jo.get("options").getAsJsonObject().get("errorMsg").isJsonNull()){
					String errorMsg=jo.get("options").getAsJsonObject().get("errorMsg").getAsString();
					if(errorMsg.contains("验证码过期")){
						response.head.rtnCode = "900001";
						response.head.rtnMsg = "验证码错误";
						return response.toJson();
					}else{
						response.head.rtnCode = "900006";
						response.head.rtnMsg = errorMsg;
						return response.toJson();
					}
				}else if(jo.get("options").getAsJsonObject().get("code").getAsInt()!=1){
					response.head.rtnCode = "900002";
					response.head.rtnMsg = "用户名或密码错误";
					return response.toJson();
				} 
			} 
	    }else{
	    	response.head.rtnCode = "999999"; 
	    	response.head.rtnMsg = "系统返回异常"; 
	    }  
		return response.toJson();
    }  
}
